<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\SysUserDesigner;

/**
 * SysUserDesignerSearch2 represents the model behind the search form about `backend\models\SysUserDesigner`.
 */
class SysUserDesignerSearch2 extends SysUserDesigner
{
    public function attributes()
    {
        // add related fields to searchable attributes
        return array_merge(parent::attributes(), ['time0.start_time','time0.end_time','tel0.tel']);
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['uid', 'apply_time', 'image_idcard_a', 'image_idcard_b', 'image_bcard', 'audit_state', 'audit_uid', 'audit_time', 'statues'], 'integer'],
            [['name', 'uid','tel0.tel','address'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = SysUserDesigner::find()->joinWith(['tel0'])->join('INNER JOIN','user_pay_vip AS time0','user_id = uid');
        
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        //return $dataProvider;
        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'uid' => $this->uid,
            'name' => $this->name,
        ]);

        $query->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'uid', $this->uid])
            ->andFilterWhere(['like', 'address', $this->address])
            ->andFilterWhere(['like', 'tel', $this->getAttribute('tel0.tel')]);

        return $dataProvider;
    }
}
